from WALF import WALF
from WRMF import WRMF
import pandas as pd
import numpy as np

if __name__=='__main__':
    ratings=pd.read_table('event_weight.csv',sep=',').sample(100)
    # ratings.to_csv("event_weight.csv")


    train = ratings.pivot_table(values='count', index='visitorid', columns='itemid').fillna(0)
    print(train)
    walf=WALF(train.to_numpy(),5,0.001,0.005)
    walf.iteration_train(10)
    # for i in range(len(test.index)):
    #     for j in range(len(train.index)):
    #         if test.index[i]==train.index[j]:
    #             print(test.index[i])
    #             print(train.loc[test.index[i]])


    userId=int(input("请输入需要预测的userId:"))
    top=int(input('请输入需要预测几个:'))
    # 将userId和训练的下标进行对应
    userIndex=0

    for i in range(len(train.index)):
        if train.index[i]==userId:
            userIndex=i

    Top_index=walf.TopN(top,userIndex)
    print(Top_index)

    # print(walf.Recall(userIndex))
    # 将得到的topN的电影id和电影名称对应
    # for i in Top_index:
    #     print(ratings[ratings['movieId']==i].iloc[0:]['title'].values[0])

    print(2/7)